home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Sound / Cheap Studio / _headers / DBFF.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-15  |  12.8 KB  |  341 lines  |  [TEXT/CWIE]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Headers for routines called to play a sound from disk using DBFF functions.
  5. **
  6. **    by Mark Cookson, Apple Developer Technical Support
  7. **
  8. **    File:    DBFF.h
  9. **
  10. **    Copyright ©1996 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "Apple Sample
  17. **    Code" after having made changes. If you're going to re-distribute the
  18. **    source, we require that you make it clear in the source that the code
  19. **    was descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. /*
  23.     This file contains the function prototypes so that if you built the source
  24.     into a library you would only need this file and DBFF_Errors.h to compile
  25.     your source.  This also provides for some data hiding by typedef'ing the
  26.     SoundInfoPtr into just a Ptr.  This file is not needed if you are not using
  27.     the code to build a library.
  28. */
  29.  
  30. #ifndef __DBFF__
  31. #define __DBFF__
  32.  
  33. #include <Sound.h>
  34. #include "DBFF_Errors.h"
  35.  
  36. #define kFreeMem            1
  37. #define kCloseFile            2
  38.  
  39. typedef Ptr SoundInfoPtr;
  40.  
  41. /* Function definitions */
  42.  
  43. /*    Purpose:        This creates a new SoundInfo structure and initializes
  44.                     it by calling ASoundInit.
  45.     Side Effects:    None.
  46. */
  47. /*-----------------------------------------------------------------------*/
  48. SoundInfoPtr    ASoundNew                (OSErr *theErr);
  49. /*-----------------------------------------------------------------------*/
  50.  
  51. /*
  52.     Purpose:        Display a StandardFile dialog to select an AIFF file.
  53.                     Open the file selected by the user.
  54.     Side Effects:    None.
  55. */
  56. /*-----------------------------------------------------------------------*/
  57. OSErr            ASoundGetFileToPlay        (SoundInfoPtr theSoundInfo);
  58. /*-----------------------------------------------------------------------*/
  59.  
  60. /*
  61.     Purpose:        Checks a file to see if its header can be parsed
  62.                     and the file can be played.
  63.                     
  64.                     This will return an error if the sound will not play,
  65.                     returning noErr means that sound will play.
  66.     Side Effects:    None.
  67. */
  68. /*-----------------------------------------------------------------------*/
  69. OSErr            ASoundCanThisPlay        (CInfoPBPtr theFileInfo);
  70. /*-----------------------------------------------------------------------*/
  71.  
  72. /*
  73.     Purpose:        Wrapper function called to get ready to play a sound.
  74.                     Use this if you want to make sure that there is enough
  75.                     memory to play the sound.
  76.     Side Effects:    This will call routines that will allocate memory needed
  77.                     to all of the various structures needed by the Sound Manager
  78.                     and memory to be used as the sounds' buffers.
  79. */
  80. /*-----------------------------------------------------------------------*/
  81. OSErr            ASoundReadyForPlaying    (SoundInfoPtr theSoundInfo,
  82.                                         unsigned long bufferSize);
  83. /*-----------------------------------------------------------------------*/
  84.  
  85. /*
  86.     Purpose:        Call this after you have called ASoundReadyForPlaying to
  87.                     start playing the sound you prepaired.
  88.     Side Effects:    Starts the sound playing.
  89. */
  90. /*-----------------------------------------------------------------------*/
  91. OSErr            ASoundPlay                (SoundInfoPtr theSoundInfo);
  92. /*-----------------------------------------------------------------------*/
  93.  
  94. /*
  95.     Purpose:        Wrapper function called to start playing a sound.
  96.                     Use this if you are pretty sure the sound will play, or
  97.                     just don't care specifically what goes wrong.
  98.     Side Effects:    This will call routines that will allocate memory needed
  99.                     to all of the various structures needed by the Sound Manager
  100.                     and memory to be used as the sounds' buffers.
  101. */
  102. /*-----------------------------------------------------------------------*/
  103. OSErr            ASoundStartPlaying        (SoundInfoPtr theSoundInfo,
  104.                                         unsigned long bufferSize);
  105. /*-----------------------------------------------------------------------*/
  106.  
  107. /*
  108.     Purpose:        Stops the currently playing sound.
  109.     Side Effects:    Stopping the currently playing sound will cause the
  110.                     sound completion routine to run.
  111. */
  112. /*-----------------------------------------------------------------------*/
  113. OSErr            ASoundStop                (SoundInfoPtr theSoundInfo);
  114. /*-----------------------------------------------------------------------*/
  115.  
  116. /*
  117.     Purpose:        Wrapper so the user doesn't have to keep track of if
  118.                     the sound is playing or not.
  119.     Side Effects:    If resuming a sound and the user had also called
  120.                     ASoundPauseForAdjust this will reinstall the sound
  121.                     completion callback.
  122. */
  123. /*-----------------------------------------------------------------------*/
  124. OSErr            ASoundPause                (SoundInfoPtr theSoundInfo);
  125. /*-----------------------------------------------------------------------*/
  126.  
  127. /*
  128.     Purpose:        If the sound is paused, resume playing.  If the sound is
  129.                     playing, pause playing.
  130.                     This differs from ASoundPause because it actually stops
  131.                     the sound instead of pausing it.  When the sound is
  132.                     paused for adjusting you can reset where the sound will
  133.                     next start playing from without having to play the
  134.                     remainder of the current buffer.  This routine is used
  135.                     for the QuickTime style playing.
  136.     Side Effects:    Removes the callback from the sound channel because
  137.                     otherwise while adjusting the sound the Sound Manager
  138.                     would call our clean up routine.
  139.                     When resuming a sound ASoundStartPlaying will install
  140.                     our callback routine if necessary (if the sound wasn't
  141.                     already paused).
  142. */
  143. /*-----------------------------------------------------------------------*/
  144. OSErr            ASoundPauseForAdjust    (SoundInfoPtr theSoundInfo);
  145. /*-----------------------------------------------------------------------*/
  146.  
  147. /*
  148.     Purpose:        Sound is done playing, dispose of the memory we no
  149.                     longer need.
  150.     Side Effects:    None.
  151. */
  152. /*-----------------------------------------------------------------------*/
  153. OSErr            ASoundDonePlaying        (SoundInfoPtr theSoundInfo,
  154.                                         unsigned long options);
  155. /*-----------------------------------------------------------------------*/
  156.  
  157. /*
  158.     Purpose:        Returns the channel for the sound in case you want to
  159.                     send it specific commands.
  160.     Side Effects:    None.
  161. */
  162. /*-----------------------------------------------------------------------*/
  163. SndChannelPtr    ASoundGetChan            (SoundInfoPtr theSoundInfo);
  164. /*-----------------------------------------------------------------------*/
  165.  
  166. /*
  167.     Purpose:        Returns the name of the file containing the currently
  168.                     playing sound.
  169.     Side Effects:    None.
  170. */
  171. /*-----------------------------------------------------------------------*/
  172. OSErr            ASoundGetSoundName        (SoundInfoPtr theSoundInfo,
  173.                                         Str255 theName);
  174. /*-----------------------------------------------------------------------*/
  175.  
  176. /*
  177.     Purpose:        Gets the number of the current buffer
  178.                     (in the range 1 to ASoundGetNumBuffers()) of the
  179.                     currently playing sound.
  180.     Side Effects:    None.
  181. */
  182. /*-----------------------------------------------------------------------*/
  183. long            ASoundGetCurBuffer        (SoundInfoPtr theSoundInfo);
  184. /*-----------------------------------------------------------------------*/
  185.  
  186. /*
  187.     Purpose:        Sets which buffer should be the next buffer to play
  188.                     from (in the range 1 to ASoundGetNumBuffers())
  189.                     for the currently playing sound.
  190.     Side Effects:    None.
  191. */
  192. /*-----------------------------------------------------------------------*/
  193. OSErr            ASoundSetCurBuffer        (SoundInfoPtr theSoundInfo,
  194.                                         long newValue);
  195. /*-----------------------------------------------------------------------*/
  196.  
  197. /*
  198.     Purpose:        Gets the number of buffers that the currently playing
  199.                     sound will need to play in its entirety.
  200.     Side Effects:    None.
  201. */
  202. /*-----------------------------------------------------------------------*/
  203. long            ASoundGetNumBuffers        (SoundInfoPtr theSoundInfo);
  204. /*-----------------------------------------------------------------------*/
  205.  
  206. /*
  207.     Purpose:        Gets the length (in bytes) of the currently playing
  208.                     sound.  This number does not include any header bytes.
  209.     Side Effects:    None.
  210. */
  211. /*-----------------------------------------------------------------------*/
  212. long            ASoundGetNumTotalBytes    (SoundInfoPtr theSoundInfo);
  213. /*-----------------------------------------------------------------------*/
  214.  
  215. /*
  216.     Purpose:        Gets the number of bytes that will be played by the end
  217.                     of the current buffer of the currently playing sound.
  218.     Side Effects:    None.
  219. */
  220. /*-----------------------------------------------------------------------*/
  221. long            ASoundGetBytesCopied    (SoundInfoPtr theSoundInfo);
  222.  
  223. /*
  224.     Purpose:        Sets the location in the file where the next buffer
  225.                     should be filled from for the currently playing sound.
  226.     Side Effects:    None.
  227. */
  228. /*-----------------------------------------------------------------------*/
  229. OSErr            ASoundSetBytesCopied    (SoundInfoPtr theSoundInfo,
  230.                                         long newValue);
  231. /*-----------------------------------------------------------------------*/
  232.  
  233. /*
  234.     Purpose:        Gets the size of a buffer of the currently playing
  235.                     sound.  Multiply by two to know how much memory is
  236.                     reserved for buffering the currently playing sound.
  237.     Side Effects:    None.
  238. */
  239. /*-----------------------------------------------------------------------*/
  240. long            ASoundGetBufferSize        (SoundInfoPtr theSoundInfo);
  241. /*-----------------------------------------------------------------------*/
  242.  
  243. /*
  244.     Purpose:        Gets the UPP for the function that should be called when
  245.                     the currently playing sound finishes.
  246.     Side Effects:    None.
  247. */
  248. /*-----------------------------------------------------------------------*/
  249. SndCallBackUPP    ASoundGetSoundCallBack    (SoundInfoPtr theSoundInfo);
  250. /*-----------------------------------------------------------------------*/
  251.  
  252. /*
  253.     Purpose:        Sets the function that should be called when the the
  254.                     currently playing sound finishes.
  255.     Side Effects:    None.
  256. */
  257. /*-----------------------------------------------------------------------*/
  258. OSErr            ASoundSetSoundCallBack    (SoundInfoPtr theSoundInfo,
  259.                                         void* newValue);
  260. /*-----------------------------------------------------------------------*/
  261.  
  262. /*
  263.     Purpose:        Says to play the currently playing sound backwards
  264.                     (reverses the sound in the buffer).
  265.     Side Effects:    Takes effect when the next sound buffer gets filled.
  266. */
  267. /*-----------------------------------------------------------------------*/
  268. OSErr            ASoundPlayBackwards        (SoundInfoPtr theSoundInfo,
  269.                                         Boolean newValue);
  270. /*-----------------------------------------------------------------------*/
  271.  
  272. /*
  273.     Purpose:        Returns true if the currently playing sound's buffer
  274.                     is set to be reversed.
  275.     Side Effects:    None.
  276. */
  277. /*-----------------------------------------------------------------------*/
  278. Boolean            ASoundIsBackwards        (SoundInfoPtr theSoundInfo);
  279. /*-----------------------------------------------------------------------*/
  280.  
  281. /*
  282.     Purpose:        Returns true if the sound has finished playing.
  283.     Side Effects:    None.
  284. */
  285. /*-----------------------------------------------------------------------*/
  286. Boolean            ASoundIsDone            (SoundInfoPtr theSoundInfo);
  287. /*-----------------------------------------------------------------------*/
  288.  
  289. /*
  290.     Purpose:        Changes the volume of the currently playing sound.
  291.                     The values you pass in are added to the current values.
  292.                     Negitive values will decrease the volume, positive values
  293.                     will increase the volume.
  294.     Side Effects:    None.
  295. */
  296. /*-----------------------------------------------------------------------*/
  297. OSErr            ASoundChangeVolume        (SoundInfoPtr theSoundInfo,
  298.                                         unsigned short leftVol,
  299.                                         unsigned short rightVol);
  300. /*-----------------------------------------------------------------------*/
  301.  
  302. /*
  303.     Purpose:        Gets the volume of the currently playing sound.
  304.     Side Effects:    None.
  305. */
  306. /*-----------------------------------------------------------------------*/
  307. OSErr            ASoundGetVolume            (SoundInfoPtr theSoundInfo,
  308.                                         unsigned short *leftVol,
  309.                                         unsigned short *rightVol);
  310. /*-----------------------------------------------------------------------*/
  311.  
  312. /*
  313.     Purpose:        Sets the volume of the currently playing sound.
  314.     Side Effects:    None.
  315. */
  316. /*-----------------------------------------------------------------------*/
  317. OSErr            ASoundSetVolume            (SoundInfoPtr theSoundInfo,
  318.                                         unsigned short leftVol,
  319.                                         unsigned short rightVol);
  320. /*-----------------------------------------------------------------------*/
  321.  
  322. /*
  323.     Purpose:        Gets the rate multiplier of the currently playing sound.
  324.     Side Effects:    None.
  325. */
  326. /*-----------------------------------------------------------------------*/
  327. OSErr            ASoundGetRateMul        (SoundInfoPtr theSoundInfo,
  328.                                         UnsignedFixed *theRateMul);
  329. /*-----------------------------------------------------------------------*/
  330.  
  331. /*
  332.     Purpose:        Gets the rate multiplier of the currently playing sound.
  333.     Side Effects:    None.
  334. */
  335. /*-----------------------------------------------------------------------*/
  336. OSErr            ASoundSetRateMul        (SoundInfoPtr theSoundInfo,
  337.                                         UnsignedFixed theRateMul);
  338. /*-----------------------------------------------------------------------*/
  339.  
  340. #endif
  341.